package cn.iocoder.yudao.module.orderview.convert.orderview;

import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.orderview.controller.admin.vo.orderview.OrderViewRespVO;
import cn.iocoder.yudao.module.orderview.dal.redis.orderview.snapshot.OrderViewAggregationSnapshot;
import cn.iocoder.yudao.module.product.api.product.dto.ProductRespDTO;
import cn.iocoder.yudao.module.product.mq.message.ProductInfoSendMessage;
import cn.iocoder.yudao.module.promotion.api.promotion.dto.PromotionRespDTO;
import cn.iocoder.yudao.module.promotion.mq.message.PromotionInfoSendMessage;
import cn.iocoder.yudao.module.stock.api.stock.dto.StockRespDTO;
import cn.iocoder.yudao.module.stock.mq.message.StockInfoSendMessage;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

@Mapper
public interface OrderViewConvert {

    OrderViewConvert INSTANCE = Mappers.getMapper(OrderViewConvert.class);

    default OrderViewRespVO convert(ProductRespDTO productRespDTO, StockRespDTO stockRespDTO, PromotionRespDTO promotionRespDTO) {
        OrderViewRespVO orderViewRespVO = BeanUtils.toBean(productRespDTO, OrderViewRespVO.class);
        if (orderViewRespVO != null) {
            orderViewRespVO.setProductId(productRespDTO.getId());
            orderViewRespVO.setProductName(productRespDTO.getName());
            if (stockRespDTO != null) {
                BeanUtils.copyProperties(stockRespDTO, orderViewRespVO);
            }
            if (promotionRespDTO != null) {
                BeanUtils.copyProperties(promotionRespDTO, orderViewRespVO);
            }
        }
        return orderViewRespVO;
    }


    default OrderViewRespVO convert(OrderViewAggregationSnapshot orderView) {
        OrderViewRespVO vo = new OrderViewRespVO();
        if (orderView != null) {
            ProductInfoSendMessage productInfo = orderView.getProductInfo();
            if (productInfo != null) {
                BeanUtils.copyProperties(productInfo, vo);
                vo.setProductName(productInfo.getName());
            }
            PromotionInfoSendMessage promotionInfo = orderView.getPromotionInfo();
            if (promotionInfo != null) {
                BeanUtils.copyProperties(promotionInfo, vo);
            }
            StockInfoSendMessage stockInfo = orderView.getStockInfo();
             if (stockInfo != null) {
                BeanUtils.copyProperties(stockInfo, vo);
            }
        }
        return vo;
    }

}
